﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

using EFCachingProvider;
using EFProviderWrapperToolkit;
using EFTracingProvider;
using EFCachingProvider.Web;
using EFCachingProvider.Caching;
using System.ComponentModel.DataAnnotations;
using GPMS.Model.Validator;
using GPMS.Model;

namespace GPMS.Web
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Main",                                              // Route name
                "{controller}/{action}/{id}/{page}",                           // URL with parameters
                new { controller = "Home", action = "Index" }, // Parameter defaults
                new { id = @"\d{0,}", page = @"\d{0,}" }
            );
            routes.MapRoute(
                "Default", // 路由名称
                "{controller}/{action}/{id}", // 带有参数的 URL
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            EFTracingProviderConfiguration.LogToFile = Server.MapPath("~/Logs/" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ".txt");
            EFCachingProviderConfiguration.DefaultCache = new AspNetCache();
            EFCachingProviderConfiguration.DefaultCachingPolicy = CachingPolicy.CacheAll;

            DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(DataTypeAttribute), typeof(DataTypeValidator));
            DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(RemoteCustom), typeof(RemoteValidator));

           // ModelMetadataProviders.Current = new GPMS.Model.FieldTemplateMetadataProvider();  
        }
    }
}